index.js ➔ resetFrame   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
2
3
'use strict';
4
5
function isEmpty(x) {
6
    return (
7
        typeof x === 'undefined' ||
8
        x === null ||
9
        x === 'null' ||
10
        x === 'undefined' ||
11
        x === false ||
12
        x.length === 0 ||
13
        x === ''||
14
        (x === "object" && Object.key(x).length === 0) ||
15
        (x && Object.keys(x).length === 0
16
        && Object.getPrototypeOf(x) === Object.prototype)
17
    );
18
}
19
20
function isJson(str) {
21
    try {
22
      str=JSON.parse(str);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
23
    } catch (e) {
24
        return str;
25
    }
26
}
27
28
function checkEmptyHtml(id, checkChildNode = false) {
29
    const elem = document.querySelector(`${id}`);
30
    if (elem === null || elem === undefined) {
31
        return true;
32
    } else if (elem && elem.childNodes.length > 0 && checkChildNode) {
33
        return true;
34
    }
35
    return false;
36
}
37
38
function prepareFrame(checkout_url) {
39
    const ifrm = document.createElement("iframe");
40
    let url = new URL(checkout_url);
0 ignored issues
show
Bug introduced by
The variable URL seems to be never declared. If this is a global, consider adding a /** global: URL */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
41
42
    ifrm.setAttribute("src", url.href);
43
    ifrm.setAttribute("id", 'bSecurePaymentPluginEmbeddedIframe');
44
    ifrm.setAttribute("name", 'bSecurePaymentPluginEmbeddedIframe');
45
    ifrm.style.position = "absolute";
46
    ifrm.style.border = "none";
47
    ifrm.style.top = "0";
48
    ifrm.style.left = "0";
49
    ifrm.style.width = "100%";
50
    ifrm.style.height = "100%";
51
    document.getElementById("bSecurePaymentPluginContainer").appendChild(ifrm);
52
}
53
54
55
function resetFrame() {
56
    document.getElementById("bSecurePaymentPluginContainer").remove();
57
}
58
59
module.exports = {
60
    isEmpty: isEmpty,
61
    isJson: isJson,
62
    checkEmptyHtml: checkEmptyHtml,
63
    prepareFrame: prepareFrame,
64
    resetFrame: resetFrame,
65
};